package com.itheima.a13waitandnotify;

public class Cook extends Thread{

    public void run(){

        while(true) {
            synchronized (Desk.lock) {
                if (Desk.count == 0 ) {
                    break ;
                } else {
                    if (Desk.FoodFlag == 1) {
                        //有食物 等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        //没有就做
                        System.out.println("厨师做了一碗面条...");
                        Desk.FoodFlag = 1;
                        Desk.lock.notifyAll();
                    }
                }
            }
        }
    }
}
